#名称:Backdream
#时间2022/12/26  20:14

class BasePage:

    def __init__(self, driver):
        self.driver = driver
        self.size = self.driver.get_window_size()
        self.width = self.size.get("width")
        self.height = self.size.get("height")

    def find_element(self, locator):
        """根据传递的定位器，查找元素"""
        return self.driver.find_element(*locator)

    #上下滑动操作
    def swipe_up(self, duration=2):  # 向上滑动 X不变 Y从0.8到0.2 其他类推
        self.driver.swipe(start_x=self.width * 0.5, start_y=self.height * 0.84
                          , end_x=self.width * 0.5, end_y=self.height * 0.11,
                          duration=duration * 1000)

    def swipe_down(self, duration=2):
        self.driver.swipe(start_x=self.width * 0.5, start_y=self.height * 0.2
                          , end_x=self.width * 0.5, end_y=self.height * 0.8,
                          duration=duration * 1000)

    def swipe_left(self, duration=2):
        self.driver.swipe(start_x=self.width * 0.8, start_y=self.height * 0.5
                          , end_x=self.width * 0.2, end_y=self.height * 0.5,
                          duration=duration * 1000)

    def swipe_right(self, duration=2):
        self.driver.swipe(start_x=self.width * 0.2, start_y=self.height * 0.5
                          , end_x=self.width * 0.8, end_y=self.height * 0.5,
                          duration=duration * 1000)